package com.kamaro.dao.implementacao;

import com.kamaro.dao.EmbalagemDAO;
import com.kamaro.dao.HibernateSessionFactory;
import com.kamaro.model.Embalagem;
import org.hibernate.Session;

import java.util.List;

/**
 * Created by vanessa.chan on 07/04/14.
 */
public class HibernateEmbalagemDAO implements EmbalagemDAO{


    @Override
    public List<Embalagem> listarAll() {
        Session session = new HibernateSessionFactory().getSession();
         return session.createQuery("from Embalagem e order by e.descricao").list();

    }

    @Override
    public void save(Embalagem e) {
        Session session = new HibernateSessionFactory().getSession();
        session.beginTransaction();
        session.save(e);
        session.getTransaction().commit();

    }

    @Override
    public void update(Embalagem e) {
        Session session = new HibernateSessionFactory().getSession();
        session.beginTransaction();
        session.update(e);
        session.getTransaction().commit();
    }

    @Override
    public void excluir(Embalagem e) {
        Session session = new HibernateSessionFactory().getSession();
        session.beginTransaction();
        session.delete(e);
        session.getTransaction().commit();

    }
}
